home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Periodicals / CSMP / C.S.M.P. Digest, Issue 3.005 < prev    next >
Internet Message Format  |  1994-06-09  |  69KB

  1. From: pottier@clipper.ens.fr (Francois Pottier)
  2. Subject: C.S.M.P. Digest, Issue 3.005
  3. Date: Wed, 16 Mar 94 16:43:25 MET
  4.  
  5. C.S.M.P. Digest             Wed, 16 Mar 94       Volume 3 : Issue 5
  6.  
  7. Today's Topics:
  8.  
  9.         AppleScript: Compiled Script of Applets?
  10.         Communications Tool Box Experts?
  11.         Execution speed of compiled code
  12.         How do I : find out more about an open resource file ?
  13.         PopUpMenuControl v. 'mctb', help help
  14.         TextEdit caret
  15.         What language should I learn?
  16.  
  17.  
  18.  
  19. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  20. (pottier@clipper.ens.fr).
  21.  
  22. The digest is a collection of article threads from the internet newsgroup
  23. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  24. regularly and want an archive of the discussions.  If you don't know what a
  25. newsgroup is, you probably don't have access to it.  Ask your systems
  26. administrator(s) for details.  If you don't have access to news, you may
  27. still be able to post messages to the group by using a mail server like
  28. anon.penet.fi (mail help@anon.penet.fi for more information).
  29.  
  30. Each issue of the digest contains one or more sets of articles (called
  31. threads), with each set corresponding to a 'discussion' of a particular
  32. subject.  The articles are not edited; all articles included in this digest
  33. are in their original posted form (as received by our news server at
  34. nef.ens.fr).  Article threads are not added to the digest until the last
  35. article added to the thread is at least two weeks old (this is to ensure that
  36. the thread is dead before adding it to the digest).  Article threads that
  37. consist of only one message are generally not included in the digest.
  38.  
  39. The digest is officially distributed by two means, by email and ftp.
  40.  
  41. If you want to receive the digest by mail, send email to listserv@ens.fr
  42. with no subject and one of the following commands as body:
  43.     help                        Sends you a summary of commands
  44.     subscribe csmp-digest Your Name    Adds you to the mailing list
  45.     signoff csmp-digest            Removes you from the list
  46. Once you have subscribed, you will automatically receive each new
  47. issue as it is created.
  48.  
  49. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  50. Questions related to the ftp site should be directed to
  51. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  52. digest are available there.
  53.  
  54. Also, the digests are available to WAIS users as comp.sys.mac.programmer.src.
  55.  
  56.  
  57. -------------------------------------------------------
  58.  
  59. >From yjc@po.cwru.edu (Jerome Chan)
  60. Subject: AppleScript: Compiled Script of Applets?
  61. Date: Sat, 26 Feb 1994 13:05:59 -0500
  62. Organization: TofuSoft
  63.  
  64. What are the advantages of Compiled scripts and Applets? Are they both the
  65. same? Can I run multiple scripts/applets at a time?
  66.  
  67. -- 
  68.  The Evil Tofu (Only Human)
  69.  
  70. +++++++++++++++++++++++++++
  71.  
  72. >From js12@gte.com (John Schettino)
  73. Date: Mon, 28 Feb 1994 13:02:42 GMT
  74. Organization: GTE Labs, Waltham MA
  75.  
  76. In article <yjc-260294130559@b61539.student.cwru.edu>
  77. yjc@po.cwru.edu (Jerome Chan) writes:
  78.  
  79. > What are the advantages of Compiled scripts and Applets? Are they both the
  80. > same? Can I run multiple scripts/applets at a time?
  81. > -- 
  82. >  The Evil Tofu (Only Human)
  83.  
  84. compiled scripts correspond to reusable compiled libs in other
  85. languages. You cannot "run" them, you access them using:
  86.  
  87. -- this is meant to be applescript
  88. set myfuncts to load script file "myhd:mylibs:functs"
  89.  
  90. -- where "myhd:mylibs:functs" is the full path to the file you saved 
  91. -- as a compiled script.
  92.  
  93. -- assume that there are two handlers in the file functs called foo and
  94. bar. you
  95. -- access them using:
  96. myfuncts's foo()
  97. myfuncts's bar()
  98.  
  99. -- 'load script' is an applescript extention (found in System
  100. Folder:Extentions:Scripting Additions:Load Script) and has a dictionary
  101. that you can see by droping this file on the script editor.
  102.  
  103.  
  104. John Schettino - js12@gte.com
  105. GTE Laboratories, Inc
  106.  
  107. +++++++++++++++++++++++++++
  108.  
  109. >From minshull.m@applelink.apple.com (Mark Minshull)
  110. Date: Tue, 1 Mar 1994 23:02:53 GMT
  111. Organization: OpenDoc Engineering
  112.  
  113. In article <CLxqwK.GBL@gte.com>, js12@gte.com (John Schettino) wrote:
  114.  
  115. > In article <yjc-260294130559@b61539.student.cwru.edu>
  116. > yjc@po.cwru.edu (Jerome Chan) writes:
  117. > > What are the advantages of Compiled scripts and Applets? Are they both the
  118. > > same? Can I run multiple scripts/applets at a time?
  119. > > 
  120. > > -- 
  121. > >  The Evil Tofu (Only Human)
  122. > compiled scripts correspond to reusable compiled libs in other
  123. > languages. You cannot "run" them, you access them using:
  124.  
  125. You *can* run compiled scripts by using the "run script" command, or
  126. "telling" the script object to run.  For example, consider the script
  127. below, saved in the file "hd:folder:hello world" as a compiled script: 
  128.  
  129.          display dialog "hello world"
  130.  
  131.       on foo(x)
  132.         return x + 2
  133.    end foo
  134.  
  135.       on bar(y)
  136.         return y - 2
  137.    end bar
  138.  
  139. You can execute this as follows:
  140.  
  141.       run script file "hd:folder:hello world"
  142.  
  143. which would display a dialog.  If you want to load the script as a library
  144. and run it you would script:
  145.  
  146.       set myFooLib to load script file "hd:folder:hello world"
  147.       tell myFooLib
  148.       run         -- display's a dialog
  149.       foo(2)      --   => 4
  150.       bar(2)      --   => 0
  151.    end tell
  152.  
  153. Finally, "applets" are AppleScripts saved as small applications.  You can
  154. have any number of them running at once (up to the limit of memory).  If
  155. it's a "stay open" script application one can access it's handlers as
  156. follows:
  157.  
  158.    tell application "hello world"    -- launches application if not running
  159.       run         -- display's a dialog
  160.       foo(2)      --   => 4
  161.       bar(2)      --   => 0
  162.             quit        -- quit's the script application
  163.    end tell     
  164.  
  165. Mark
  166. -- 
  167. Mark Minshull                       :
  168. OpenDoc Engineering Manager         :          Apple usually doesn't care 
  169. Apple Computer, Inc.                :          what I say... When they do
  170. 1 Infinite Loop, MS 303-3A          :          my opinions are my own.
  171. Cupertino, CA  95014                :    
  172.  
  173. +++++++++++++++++++++++++++
  174.  
  175. >From js12@gte.com (John Schettino)
  176. Date: Wed, 2 Mar 1994 12:36:36 GMT
  177. Organization: GTE Labs, Waltham MA
  178.  
  179. In article <minshull.m-010394150253@minshullmac.apple.com>
  180. minshull.m@applelink.apple.com (Mark Minshull) writes:
  181.  
  182. > In article <CLxqwK.GBL@gte.com>, js12@gte.com (John Schettino) wrote:
  183. > > In article <yjc-260294130559@b61539.student.cwru.edu>
  184. > > yjc@po.cwru.edu (Jerome Chan) writes:
  185. > > 
  186. > > > What are the advantages of Compiled scripts and Applets? Are they both the
  187. > > > same? Can I run multiple scripts/applets at a time?
  188. > > > 
  189. > > > -- 
  190. > > >  The Evil Tofu (Only Human)
  191. > > 
  192. > > compiled scripts correspond to reusable compiled libs in other
  193. > > languages. You cannot "run" them, you access them using:
  194. > > 
  195. > You *can* run compiled scripts by using the "run script" command, or
  196. > "telling" the script object to run.  For example, consider the script
  197. > below, saved in the file "hd:folder:hello world" as a compiled script: 
  198. >                  display dialog "hello world"
  199. >           on foo(x)
  200. >             return x + 2
  201. >    end foo
  202. >           on bar(y)
  203. >             return y - 2
  204. >    end bar
  205. > You can execute this as follows:
  206. >           run script file "hd:folder:hello world"
  207. > which would display a dialog.  If you want to load the script as a library
  208. > and run it you would script:
  209. >           set myFooLib to load script file "hd:folder:hello world"
  210. >           tell myFooLib
  211. >       run         -- display's a dialog
  212. >       foo(2)      --   => 4
  213. >       bar(2)      --   => 0
  214. >    end tell
  215.  
  216. Yes, you can *load* a compiled script into your script and send it a
  217. run command, but I guessed that he meant "Can you run a compiled script
  218. *from the finder*" With this interpretation, the answer is "no". Your
  219. answer is correct, and (I think) so is mine!
  220.  
  221. John Schettino - js12@gte.com
  222. GTE Laboratories, Inc
  223.  
  224. ---------------------------
  225.  
  226. >From tel@adimail.uucp (Terry Monks)
  227. Subject: Communications Tool Box Experts?
  228. Date: Mon, 28 Feb 1994 19:08:40 GMT
  229. Organization: Automata Design, Inc.
  230.  
  231. Are there any CTB experts out there? I need to send a setup string
  232. to my USR modem from with a program. Not the CTB setup string,
  233. but a AT&B1&H1 sort of thing. I know I can change the modem type
  234. to Custom and change the modem setup string, but how do you do
  235. this from within a CTB program? And where (if anywhere) is this
  236. documented. How does the Apple Modem Tool know about the different
  237. modes, and can I add one of my own.
  238.  
  239. I do (of course) have the Inside Mac CTB document, that is silent
  240. on these interesting points...
  241.  
  242. Tel
  243.  
  244. -- 
  245. Terry Monks    tel@adiva.com    Automata Design Inc    (703) 742-9400
  246.  
  247.  
  248. +++++++++++++++++++++++++++
  249.  
  250. >From ejw@pacersoft.com (Erik James Walter)
  251. Date: 1 Mar 94 21:01:43 GMT
  252. Organization: Pacer Software, Inc.
  253.  
  254. In article <1994Feb28.190840.25604@adimail.uucp> Terry Monks,
  255. tel@adimail.uucp writes:
  256. >Are there any CTB experts out there? I need to send a setup string
  257. >to my USR modem from with a program. Not the CTB setup string,
  258. >but a AT&B1&H1 sort of thing. I know I can change the modem type
  259. >to Custom and change the modem setup string, but how do you do
  260. >this from within a CTB program? And where (if anywhere) is this
  261. >documented. How does the Apple Modem Tool know about the different
  262. >modes, and can I add one of my own.
  263. >
  264. >I do (of course) have the Inside Mac CTB document, that is silent
  265. >on these interesting points...
  266. >
  267.  
  268. For starters, you could simply use the Serial tool and send the data
  269. directly
  270. to the modem.   If you look at GetConfig and SetConfig for tools, I think
  271. that you'll find the information you need on setting a custom modem and
  272. changing the tool settings.  Inside CTB doesn't say it directly, but you
  273. can pass just one or two settings in the SetConfig call and it won't
  274. affect
  275. anything but the settings you pass to it.
  276.  
  277. If you want to do it with a custom modem type, there is no way to change
  278. the
  279. modem file from CTB, but you can just open the file yourself if you so
  280. choose to (Not a good idea, however).
  281.  
  282. If timing isn't critical, why not just send the string after opening the
  283. connection??
  284.  
  285.  
  286. +-------------------------------------------++-------------------------
  287. ---+
  288. | A man gazing at the stars is at the mercy ||     Erik Walter           
  289.  | 
  290. | of every puddle on the road.              ||     Macintosh Engineer    
  291.  |
  292. | "Travel is lethal to prejudice."          ||     Pacer Software, Inc.  
  293.  |  
  294. | MARK TWAIN                                ||                           
  295.  |
  296. +-------------------------------------------++-------------------------
  297. ---+
  298.  
  299. +++++++++++++++++++++++++++
  300.  
  301. >From gurgle@netcom.com (Pete Gontier)
  302. Date: Wed, 2 Mar 1994 00:36:05 GMT
  303. Organization: cellular
  304.  
  305. I'm no CTB expert, but what the hell? This post has been here long
  306. enough that I might as well take a shot at it.
  307.  
  308. tel@adimail.uucp (Terry Monks) writes:
  309.  
  310. >Are there any CTB experts out there? I need to send a setup string
  311. >to my USR modem from with a program. Not the CTB setup string, but a
  312. >AT&B1&H1 sort of thing. I know I can change the modem type to Custom
  313. >and change the modem setup string, but how do you do this from within a
  314. >CTB program?
  315.  
  316. You don't. The whole point of the CTB is that your program does not have
  317. any control over the connection that the connection tool doesn't want
  318. you to have. In most cases, this means you have very little control.
  319. This is a feature -- you don't *want* control, because not only is
  320. control a PITA, but what you get in exchange is the ability to use your
  321. software with AppleTalk, TCP, and any other sort of connection for which
  322. you have a tool.
  323.  
  324. One thing you might try is to use the Serial tool to send AT commands,
  325. but if you'll watch the progress window as the modem tool opens a
  326. connection, you'll see it does a pretty thorough job of blowing away any
  327. previous configuration by using 'ATZ'. At least it does not do 'AT&F';
  328. you might be able to slide something past it because of that.
  329.  
  330. If I understand correctly, you might not be able to guess which serial
  331. port the modem is hooked up to, because the CTB allows programs to
  332. register serial ports which are not the modem port or the printer port.
  333. This would tend to foil attempts to tweak the modem with the Serial
  334. Manager, as well.
  335.  
  336. You might just choose to skip the modem tool entirely and assume that
  337. the serial tool is connected to a modem. You would have to write
  338. your own code to send AT commands and parse responses. This is not
  339. particularly difficult but can be frustrating if you have never done it
  340. before. Getting it really robust is another story; there are hundreds of
  341. modems out there, each with its own interpretation of the Hayes command
  342. set.
  343.  
  344. >And where (if anywhere) is this documented.
  345.  
  346. It's not. It's implicit in the way the CTB works. To explain it would be
  347. to explicitly document how to bypass the CTB.
  348.  
  349. >How does the Apple Modem Tool know about the different modes, and can I
  350. >add one of my own.
  351.  
  352. In versions earlier than 1.5, I dunno. In 1.5, just select "Modify this
  353. Menu..." from the 'Modem' popup menu. In my limited experience I have
  354. done configurations for an Okitel 9600 and a Global Village TelePort
  355. Gold. It's not hard. It's definitely the way to go if you have the
  356. option.
  357.  
  358. >I do (of course) have the Inside Mac CTB document, that is silent
  359. >on these interesting points...
  360.  
  361. That's because it's a general-case document and tries to keep its grubby
  362. little fingers out of the domain of any particular tool. :-)
  363. -- 
  364.  Pete Gontier, CTO, Integer Poet Software; gurgle@netcom.com
  365.  
  366. ---------------------------
  367.  
  368. >From schiffer@dispair.stsci.edu (Francis H. Schiffer 3rd)
  369. Subject: Execution speed of compiled code
  370. Date: Tue, 1 Mar 1994 17:54:23 GMT
  371. Organization: Self
  372.  
  373. I have noticed a number of posts recently asking about how to achieve the 
  374. best speed of processing on a Macintosh.  The responses have said little
  375. about
  376. the effects of your compiler, whereas the benchmarks published for
  377. workstations
  378. tend to focus on the effects of your compiler on benchmark speeds.  
  379.  
  380. I attempted to see what are the effects of the compiler on the execution 
  381. speeds of a small number of benchmark programs using a IIfx running A/UX.
  382. I had four compilers that I could use:
  383.      cc    = the A/UX compiler supplied by Apple and Motorola,
  384.      gcc   = the Gnu compiler version 2.5.7 ported to A/UX,
  385.      TC    = Think C version 6.0.1, and
  386.      SC++  = Symmantec C++ version 6.0.1.
  387. The programs were benchmarks that have been used for workstation
  388. benchmarking
  389. with the minimum modifications necessary to run within the MacOS and/or
  390. A/UX
  391. environment.  For A/UX that means no modifications and for the MacOS
  392. usually 
  393. only the inclusion of prototypes.  As these are ANSI style programs, the 
  394. Think console was used for output, but that processing was entirely outside
  395. the timed sections.  In each case the benchmark times the computational
  396. portion
  397. of the program for a sufficient number of iterations to ensure that the
  398. total
  399. duration time was small compared to the timing quanta (typically 
  400. 16.67 milliseconds).  In each case the application was built using the best
  401. level of optimization offered by the compiler.
  402.  
  403. The results are shown in the following table where I have normalized the
  404. results
  405. to the speed of the fastest program .  The duration is the time it took the
  406.  
  407. fastest version of the program to execute the timed portion of the
  408. benchmark.
  409.  
  410.                        cc      gcc      TC     SC++   Duration
  411. Towers of Hanoi        1.00    0.79    0.81    0.68   37.4 sec
  412. Heapsort               0.79    1.00    0.77    0.50   24.4 sec
  413. Sieve of Eratosthenes  0.91    1.00    0.97    0.76   83.3 sec
  414.  
  415. It should be noted that part of the slowness of the MacOS compiled versions
  416. may well be due to the fact that the timing routines on the A/UX side
  417. discount
  418. the system time from the running time, whereas the MacOS run times include
  419. the system time.  All of the runs were done on a lightly loaded system, so
  420. the effects should be small.  I, unfortunately, do not have the option to
  421. take
  422. down A/UX to run on a purely native MacOS to get a measure of this bias.
  423.            skip
  424. -- 
  425. Francis H Schiffer 3rd  schiffer@stsci.edu - my opinions only, those of
  426. skip@dispair.stsci.edu  stscic::schiffer   - my employer are unknown to me
  427.  
  428. ---------------------------
  429.  
  430. >From reinkeha@dunx1.ocs.drexel.edu (Harry A. Reinke)
  431. Subject: How do I : find out more about an open resource file ?
  432. Date: Wed, 23 Feb 1994 14:52:09 GMT
  433. Organization: Drexel University, Phila. Pa.
  434.  
  435. I have been having problems with some resources, I do a CountResources and
  436. I get 2 or 3 more than are available in my resource file.  The resource
  437. type is 'hdrs' so I know that the syste and other open resource files do
  438. not have any such resources.
  439.  
  440. Am I writeing a resource without removing the old ?  I remember something
  441. about if you're not carefull you can save a particular resource type and
  442. number without destroying the prvious which causes problems.
  443.  
  444. I have used HomeResFile and its return numbers that I didn't expect (like
  445. 2546 instead of 2640) but is not part of the system/ROM.  How do I find
  446. out more about an open res file if I have its ref num ?  I would love to
  447. associate a filename with the numbers returned from HomeResFile.
  448.  
  449. Thanks.
  450.  
  451.  
  452.  
  453. +++++++++++++++++++++++++++
  454.  
  455. >From walrathw@rferl.org (WalrathW)
  456. Date: 28 Feb 94 11:18:29 -0500
  457. Organization: RFE/RL Inc.
  458.  
  459. In article <CLoMMx.AE7@Dunx1.OCS.Drexel.Edu>
  460. reinkeha@dunx1.ocs.drexel.edu (Harry A. Reinke) writes:
  461.  
  462. > I have been having problems with some resources, I do a CountResources and
  463. > I get 2 or 3 more than are available in my resource file.  The resource
  464. > type is 'hdrs' so I know that the syste and other open resource files do
  465. > not have any such resources.
  466. > Am I writeing a resource without removing the old ?  I remember something
  467. > about if you're not carefull you can save a particular resource type and
  468. > number without destroying the prvious which causes problems.
  469. > I have used HomeResFile and its return numbers that I didn't expect (like
  470. > 2546 instead of 2640) but is not part of the system/ROM.  How do I find
  471. > out more about an open res file if I have its ref num ?  I would love to
  472. > associate a filename with the numbers returned from HomeResFile.
  473. > Thanks.
  474. You can use the FILE dcmd in Macsbug to accomplish this. If you don't
  475. have it, check ftp.apple.com. If you don't find it there, send mail and
  476. i'll dig it up for you.
  477.  
  478. You could also just write a little hack to walk through the FCB data
  479. structures (or better yet use _PBGetFCBInfo). I presume there is info
  480. on this in New Inside Mac:Files, and you should also find something in
  481. ThinkRef. "Debugging Macintosh Software w/ Macsbug" is a book worth
  482. having, and also another source of info on these topics.  
  483.  
  484. I started writing a little app last week to display resource chains and
  485. the resMap's of open resource files, but kind of tabled the project
  486. after finding the tool I wanted already written. I have code for
  487. walking a resMap as well as getting the file name of an open res file,
  488. given its refNum.  Mail me if you want any of this code. It's not
  489. polished since it wasn't for distribution, but I think I added some
  490. comments here and there   :-)   .
  491.  
  492. cheers,
  493. ______o0o______
  494.  Wayne Walrath
  495.  RFE/RL Inc.
  496.  
  497. +++++++++++++++++++++++++++
  498.  
  499. >From jim@brunner.wf.com (Jim Brunner)
  500. Date: 1 Mar 94 17:16:59 GMT
  501. Organization: (none)
  502.  
  503.  
  504. In article <1994Feb28.111834.340@dcvaxb.rferl.org>, you write:
  505. > In article <CLoMMx.AE7@Dunx1.OCS.Drexel.Edu>
  506. > reinkeha@dunx1.ocs.drexel.edu (Harry A. Reinke) writes:
  507. > > I have been having problems with some resources, I do a CountResources 
  508. and
  509. > > I get 2 or 3 more than are available in my resource file.  The 
  510. resource
  511. > > type is 'hdrs' so I know that the syste and other open resource files 
  512. do
  513. > > not have any such resources.
  514. > > 
  515. > > Am I writeing a resource without removing the old ?  I remember 
  516. something
  517. > > about if you're not carefull you can save a particular resource type 
  518. and
  519. > > number without destroying the prvious which causes problems.
  520.  
  521.  
  522. CountResources counts all resources in all resource files (you mention that 
  523. the type you are counting is not in other resource files like system but 
  524. you may want to do this anyway) "Count1Resources" only counts in the 
  525. current resource file.
  526.  
  527. As to if a resource file can contain the same resource type/id twice, the 
  528. answer is YES!  I had this problem once.  If you do an AddResource and the 
  529. resource already exists, there will be a second one added.  You'll need to 
  530. watch this.
  531.  
  532. ---
  533. Jim Brunner (jim@brunner.wf.com)
  534.  
  535. ---------------------------
  536.  
  537. >From first.ascent@mindlink.bc.ca (Alex Curylo)
  538. Subject: PopUpMenuControl v. 'mctb', help help
  539. Date: 28 Feb 94 01:38:42 GMT
  540. Organization: MIND LINK! - British Columbia, Canada
  541.  
  542. I have a DITL resource, used in a CTB setup, that has a popup menu control in
  543. it. Since the popup menu would look much more cool in color, I created a
  544. 'mctb' for it in ResEdit, which displays the menu correctly. But when the
  545. menu is popped up in the dialog courtesy of the Dialog Manager, it's in bogus
  546. black and white. Is there some trick to getting a popup menu control to know
  547. about an 'mctb' for its 'MENU'?
  548.  
  549. +++++++++++++++++++++++++++
  550.  
  551. >From leonardr@netcom.com (Leonard Rosenthol)
  552. Date: Mon, 28 Feb 1994 18:33:43 GMT
  553. Organization: Aladdin Systems, Inc.
  554.  
  555. In article <39602@mindlink.bc.ca>, first.ascent@mindlink.bc.ca (Alex
  556. Curylo) wrote:
  557.  
  558. > I have a DITL resource, used in a CTB setup, that has a popup menu control in
  559. > it. Since the popup menu would look much more cool in color, I created a
  560. > 'mctb' for it in ResEdit, which displays the menu correctly. But when the
  561. > menu is popped up in the dialog courtesy of the Dialog Manager, it's in bogus
  562. > black and white. Is there some trick to getting a popup menu control to know
  563. > about an 'mctb' for its 'MENU'?
  564. >
  565.      No trick - it doesn't work!   The PopUpCDEF doesn't load the 'mctb'
  566. resource due to visual problems reported in earlier versions of same...
  567.  
  568. Leonard
  569. P.S. Hey Jon - this should probably go in the FAQ!
  570. --------------------------------------------------------------------------
  571. Leonard Rosenthol                      Internet:       leonardr@netcom.com
  572. Director of Advanced Technology        AppleLink:      MACgician
  573. Aladdin Systems, Inc.                  GEnie:          MACgician
  574.  
  575. +++++++++++++++++++++++++++
  576.  
  577. >From t.g.finstad@fys.uio.no (Terje Finstad)
  578. Date: Mon, 28 Feb 1994 20:03:40
  579. Organization: Dept. Physics, Univ. Oslo
  580.  
  581. In article <leonardr-280294103343@leonardr.slip.netcom.com>,
  582. leonardr@netcom.com (Leonard Rosenthol) wrote:
  583. > In article <39602@mindlink.bc.ca>, first.ascent@mindlink.bc.ca (Alex
  584. > Curylo) wrote:
  585. > > I have a DITL resource, used in a CTB setup, that has a popup menu control in
  586. > > it. Since the popup menu would look much more cool in color, I created a
  587. > > 'mctb' for it in ResEdit, which displays the menu correctly. But when the
  588. > > menu is popped up in the dialog courtesy of the Dialog Manager, it's in bogus
  589. > > black and white. Is there some trick to getting a popup menu control to know
  590. > > about an 'mctb' for its 'MENU'?
  591. >
  592. >      No trick - it doesn't work!   The PopUpCDEF doesn't load the 'mctb'
  593. > resource due to visual problems reported in earlier versions of same...
  594.  
  595. I may have totally misunderstood,
  596. I _had similar problems to what Alex Curylo. _Now I always get colors as I
  597. want to in the PopUp.  Am I currently doing things wrong then?
  598. I am just calling insertmenu(myMenuHandle, -1) on a hit in the popup area
  599. and then PopUpMenuSelect ,  ( I've heard this is outdated, is that it? ) On
  600. startUp I just do a myMenuHandle := getmenu(kPopUpMenuID);
  601. I had previously been led to belive I should call deletemenu after the menu
  602. had been closed/hidden by PopUpMenuSelect.  This caused the color to
  603. disappear. Now it does not. The menu does not get inserted multiple times
  604. in the menu list as far as I can tell )
  605.  
  606. Terje
  607.  
  608. +++++++++++++++++++++++++++
  609.  
  610. >From mspace@netcom.com (Brian Hall)
  611. Date: Tue, 1 Mar 1994 05:37:07 GMT
  612. Organization: Mark/Space Softworks
  613.  
  614. t.g.finstad@fys.uio.no (Terje Finstad) writes:
  615.  
  616. >I may have totally misunderstood,
  617. >I _had similar problems to what Alex Curylo. _Now I always get colors as I
  618. >want to in the PopUp.  Am I currently doing things wrong then?
  619.  
  620. No, you are just doing them differnt.  Alex is using (and Leonard replied
  621. about) the Popup Menu CDEF that was introduced with the CTB and made it into
  622. system software as of 7.0.  You are doing it "by hand" so to speak. There are
  623. valid reasons for doing it that way, but most CTB apps use the CDEF since
  624. they get it for "free".
  625.  
  626. -- 
  627. __________________________________________________________________________
  628. Brian Hall                                     Internet: mspace@netcom.com
  629. Mark/Space Softworks                             AppleLink, AOL: MARKSPACE
  630. Macintosh connectivity software.   info via anon ftp netcom.com:pub/mspace
  631.  
  632. +++++++++++++++++++++++++++
  633.  
  634. >From Alexander M. Rosenberg <alexr@apple.com>
  635. Date: Wed, 2 Mar 1994 08:58:25 GMT
  636. Organization: Hackers Anonymous
  637.  
  638. In article <leonardr-280294103343@leonardr.slip.netcom.com> Leonard Rosenthol,
  639. leonardr@netcom.com writes:
  640. > > I have a DITL resource, used in a CTB setup, that has a popup menu control
  641. in
  642. > > it. Since the popup menu would look much more cool in color, I created a
  643. > > 'mctb' for it in ResEdit, which displays the menu correctly. But when the
  644. > > menu is popped up in the dialog courtesy of the Dialog Manager, it's in
  645. bogus
  646. > > black and white. Is there some trick to getting a popup menu control to
  647. know
  648. > > about an 'mctb' for its 'MENU'?
  649. > >
  650. >      No trick - it doesn't work!   The PopUpCDEF doesn't load the 'mctb'
  651. > resource due to visual problems reported in earlier versions of same...
  652.  
  653. Actually, the problem is that the Popup CDEF (as of System 7.1) doesn't keep
  654. the menu in the menulist. 'mctb' resources are menu id referential and since
  655. the popup doesn't keep and defend an id, then 'mctb's can't be used.
  656.  
  657. Note that Inside the Macintosh Communications Toolbox and Inside Macintosh VI
  658. don't say anywhere that 'mctb' resources are supported for popups. It was a
  659. fluke. :-)
  660.  
  661. The workaround is to manually load a menu and associate it with the popup.
  662. MacApp uses this technique.
  663. ---------------------------------------------------------------------------
  664. -  Alexander M. Rosenberg  - INTERNET: alexr@apple.com      - Yoyodyne    -
  665. -  330 Waverley St., Apt B - UUCP:ucbvax!apple!alexr        - Propulsion  -
  666. -  Palo Alto, CA 94301     -                                - Systems     -
  667. -  (415) 329-8463          - Nobody is my employer so       - :-)         -
  668. -  (408) 974-3110          - nobody cares what I say.       -             -
  669.  
  670. ---------------------------
  671.  
  672. >From cnowak@bonnie.ics.uci.edu (Chris)
  673. Subject: TextEdit caret
  674. Date: 19 Feb 1994 15:50:08 -0800
  675. Organization: UC Irvine Department of ICS
  676.  
  677. I am working on a program, and have run into a slight snag.  I have a textedit
  678. field on a grey background, so the caret doesn't show up very well...
  679.  
  680. I have looked for a way to maybe change its color, or make it thicker but to
  681. no avail.
  682.  
  683. Any ideas?
  684.  
  685. Thanx, 
  686. Chris
  687.  
  688. -------------------------------------------------------------------------------
  689. Chris Nowak                |Why, yes, the world does revolve around me!
  690. cnowak@bonnie.ics.uci.edu  |Unfortunately I can't control how fast it rotates. 
  691. eapu109@orion.oac.uci.edu  | ...actually, it's giving me a headache... 
  692. -------------------------------------------------------------------------------
  693.  
  694. +++++++++++++++++++++++++++
  695.  
  696. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  697. Date: 21 Feb 1994 11:56:16 +0800
  698. Organization: NCRPDA, Curtin University
  699.  
  700. cnowak@bonnie.ics.uci.edu (Chris) writes:
  701.  
  702. >I am working on a program, and have run into a slight snag.  I have a textedit
  703. >field on a grey background, so the caret doesn't show up very well...
  704.  
  705. Well, don't put the text on a grey background then!  Seriously, you shouldn't
  706. really do this without the user at least having control over the field,
  707. since the text will also be less readable.  Perhaps just use a very light grey
  708. to differentiate it from other fields or the background?
  709.  
  710. >I have looked for a way to maybe change its color, or make it thicker but to
  711. >no avail.
  712.  
  713. There is a TEHook for drawing the cursor if I remember correctly.  It's 
  714. presumably documented in NIM-TE.  It must be documented in IM somewhere,
  715. otherwise I wouldn't know about it...
  716.    Peter.
  717. -- 
  718. _______________________________________________________________________
  719. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  720.  
  721. +++++++++++++++++++++++++++
  722.  
  723. >From Here@There (Someone)
  724. Date: 1 Mar 1994 21:25:19 GMT
  725. Organization: Large Fuzzy Room
  726.  
  727. In article <2k68jg$cvq@bonnie.ics.uci.edu>, cnowak@bonnie.ics.uci.edu
  728. (Chris) wrote:
  729. > I am working on a program, and have run into a slight snag.  I have a textedit
  730. > field on a grey background, so the caret doesn't show up very well...
  731. > I have looked for a way to maybe change its color, or make it thicker but to
  732. Write a caret hook routine.  This allows you to draw the caret yourself, in
  733. this case you could change it to any color you like that would show up
  734. better against gray.  Or you could change the size.  Here's a small sample
  735. caret hook I writ a while ago, it's in assembly, sorry, but you get the
  736. point...
  737.  
  738. /* install the hook in the textedit record */
  739. (*WordHandle)->caretHook=myCaretDraw;
  740. ; The actual caret hook routine
  741.  
  742. myCaretDraw proc export
  743.  move.l (sp)+,d0             ; get the rectangle pointer
  744.  movem.l a2-a4/d3-d7,-(sp)   ; save registers
  745.  move.l d0,d3                ; store rect someplace safe
  746.  pea myBackColor
  747.  _RGBBackColor
  748. * caretOn is a global that you use to keep track of the caret state
  749. * now check your caretOn flag.  if true, turn it off, if false, turn it on 
  750.  move.w caretOn,d0
  751.  bne.s @itsOn
  752. * myForeColor is a global RGB color I was using
  753.  pea myForeColor       ; make the caret visible
  754.  _RGBForeColor
  755.  moveq #1,d0
  756.  bra.s @saveanddraw
  757. @itsOn  pea myBackColor      ; make the caret invisible
  758.  _RGBForeColor
  759.  moveq #0,d0
  760. @saveanddraw move.w d0,caretOn(a5) ; update the flag
  761.    move.l d3,-(sp)
  762.  _PaintRect
  763.  movem.l (sp)+,a2-a4/d3-d7     ; restore regs
  764.  rts     ; and go away
  765.  endp
  766.  
  767.  
  768. <TR>
  769. Somewhere, sometime
  770.  
  771. SPA FON
  772.  
  773. ---------------------------
  774.  
  775. >From lsweet@netcom.com (Lawrence Sweet)
  776. Subject: What language should I learn?
  777. Date: Mon, 21 Feb 1994 23:00:03 GMT
  778. Organization: NETCOM On-line Communication Services (408 241-9760 guest)
  779.  
  780. Hello...
  781.  
  782. I've been using the Mac for about two years and now am becoming interested in
  783. what is behind the curtain, so to speak...
  784.  
  785. I have no programming experience but I would like to learn something about how
  786. to do so, more as a hobbyist than anything else.  I have looked through a 
  787. variety of introductory programming texts for the Mac at my local bookstore,
  788. but I'm unsure which language to pursue or what book is well written enough to
  789. learn from.
  790.  
  791. Could you please give me some suggestions?
  792.  
  793. Thanks in advance, Larry
  794.  
  795. (email is appreciated, also)
  796. -- 
  797. Lawrence Sweet                               "Every wave is new until it breaks"San Diego, CA           lsweet@netcom.com             --Neil Young (1981)
  798.  
  799. +++++++++++++++++++++++++++
  800.  
  801. >From drickey@irus.rri.uwo.ca (Daniel W. Rickey)
  802. Date: 22 Feb 1994 16:59:48 GMT
  803. Organization: Imaging Research Labs
  804.  
  805.  
  806. For someone who has never programmed before, the language to start
  807. with is with Pascal.  A good book to start learning macinitosh
  808. programming
  809. is "Macinitosh Pascal Programming Primer".  I am not sure what books
  810. are
  811. good for learning to programme in Pascal.
  812.  
  813. Daniel W. Rickey
  814. drickey@.irus.rri.uwo.ca
  815.  
  816. Imaging Research Laboratories
  817. The J.P. Robarts Research Institute
  818. 100 Perth Drive
  819. London, Ontario
  820. CANADA  N6A 5K8
  821.  
  822. +++++++++++++++++++++++++++
  823.  
  824. >From 103t_english@west.cscwc.pima.edu
  825. Date: 23 Feb 94 00:10:41 MST
  826. Organization: (none)
  827.  
  828. In article <lsweetCLLJw6.AK2@netcom.com>, lsweet@netcom.com (Lawrence Sweet) writes:
  829. > Hello...
  830. > I've been using the Mac for about two years and now am becoming interested in
  831. > what is behind the curtain, so to speak...
  832. > I have no programming experience but I would like to learn something about how
  833. > to do so, more as a hobbyist than anything else.  I have looked through a 
  834. > variety of introductory programming texts for the Mac at my local bookstore,
  835. > but I'm unsure which language to pursue or what book is well written enough to
  836. > learn from.
  837. > Could you please give me some suggestions?
  838. > Thanks in advance, Larry
  839. > (email is appreciated, also)
  840. > -- 
  841. > Lawrence Sweet                               "Every wave is new until it breaks"San Diego, CA           lsweet@netcom.com             --Neil Young (1981)
  842.  
  843. At the risk of flames: learn SmallTalk/V.
  844.  
  845. It will give you access to the ToolBox, but at the same time, you will learn
  846. OOP from the ground up.
  847.  
  848.  
  849. Lawson
  850.  
  851. +++++++++++++++++++++++++++
  852.  
  853. >From gasser@masg1.epfl.ch (Laurent Gasser)
  854. Date: 23 Feb 1994 13:02:49 GMT
  855. Organization: Ecole Polytechnique Federale de Lausanne
  856.  
  857. DO NOT learn pascal from the reference given below.
  858.  
  859. The author have never used the WITH statement. In QuickDraw
  860. environement, it is incredible. Moreover, many examples are exactly
  861. illustrating bad pascal design. Il looks like they just translated C
  862. code into pascal.
  863.  
  864. If you want to learn pascal, get a book about pascal. Later on, when
  865. you consider yourself more at ease with the language, you can look
  866. around for a book about the Macintosh plateform. Don't mix both steps,
  867. you will get lost.
  868.  
  869. In article <2kddm4$462@falcon.ccs.uwo.ca>, drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  870. |> 
  871. |> For someone who has never programmed before, the language to start
  872. |> with is with Pascal.  A good book to start learning macinitosh
  873. |> programming
  874. |> is "Macinitosh Pascal Programming Primer".  I am not sure what books
  875. |> are
  876. |> good for learning to programme in Pascal.
  877. |> 
  878. |> Daniel W. Rickey
  879. |> drickey@.irus.rri.uwo.ca
  880. |> 
  881. |> Imaging Research Laboratories
  882. |> The J.P. Robarts Research Institute
  883. |> 100 Perth Drive
  884. |> London, Ontario
  885. |> CANADA  N6A 5K8
  886.  
  887. -- 
  888. Laurent Gasser (gasser@dma.epfl.ch)
  889.  
  890. I know very few ideas worth dying for, none is worth killing.
  891.  
  892. +++++++++++++++++++++++++++
  893.  
  894. >From drickey@irus.rri.uwo.ca (Daniel W. Rickey)
  895. Date: 23 Feb 1994 15:36:24 GMT
  896. Organization: Imaging Research Labs
  897.  
  898.  
  899. >DO NOT learn pascal from the reference given below.
  900.  
  901. >The author have never used the WITH statement. In QuickDraw
  902. >environement, it is incredible. Moreover, many examples are exactly
  903. >illustrating bad pascal design. Il looks like they just translated C
  904. >code into pascal.
  905.  
  906. >If you want to learn pascal, get a book about pascal. Later on, when
  907. >you consider yourself more at ease with the language, you can look
  908. >around for a book about the Macintosh plateform. Don't mix both steps,
  909. >you will get lost.
  910.  
  911. >In article <2kddm4$462@falcon.ccs.uwo.ca>, drickey@irus.rri.uwo.ca (Daniel W. >Rickey) writes:
  912. |> 
  913. |> For someone who has never programmed before, the language to start
  914. |> with is with Pascal.  A good book to start learning macinitosh
  915. |> programming
  916. |> is "Macinitosh Pascal Programming Primer".  I am not sure what books
  917. |> are
  918. |> good for learning to programme in Pascal.
  919. |> 
  920. |> Daniel W. Rickey
  921. |> drickey@.irus.rri.uwo.ca
  922. |> 
  923.  
  924.  
  925. I recommended the book as as a reasonable one for learning how to 
  926. programme the macintosh.  I agree that it is not a good one for
  927. learning
  928. Pascal.
  929. -- 
  930. >Laurent Gasser (gasser@dma.epfl.ch)
  931.  
  932. >I know very few ideas worth dying for, none is worth killing.
  933.  
  934.  
  935. Daniel W. Rickey
  936. drickey@.irus.rri.uwo.ca
  937.  
  938. Imaging Research Laboratories
  939. The J.P. Robarts Research Institute
  940. 100 Perth Drive
  941. London, Ontario
  942. CANADA  N6A 5K8
  943.  
  944. +++++++++++++++++++++++++++
  945.  
  946. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  947. Date: 24 Feb 1994 10:56:50 +0800
  948. Organization: NCRPDA, Curtin University
  949.  
  950. gasser@masg1.epfl.ch (Laurent Gasser) writes:
  951.  
  952. >DO NOT learn pascal from the reference given below.
  953.  
  954. >The author have never used the WITH statement. In QuickDraw
  955. >environement, it is incredible. Moreover, many examples are exactly
  956.  
  957. Well, I know nothing about the book, so I can't comment on that.  But
  958. I will say that not using the WITH statement is a good idea.  The WITH
  959. statement leads to lots of very subtle errors, and generally should
  960. be avoided.
  961.    Peter.
  962. -- 
  963. _______________________________________________________________________
  964. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  965.  
  966. +++++++++++++++++++++++++++
  967.  
  968. >From drickey@irus.rri.uwo.ca (Daniel W. Rickey)
  969. Date: 24 Feb 1994 15:00:54 GMT
  970. Organization: Imaging Research Labs
  971.  
  972. >In article <2kh51i$50q@ncrpda.curtin.edu.au>
  973. >peter@ncrpda.curtin.edu.au (Peter N Lewis) writes:
  974.  
  975. > gasser@masg1.epfl.ch (Laurent Gasser) writes:
  976. > >DO NOT learn pascal from the reference given below.
  977. > >The author have never used the WITH statement. In QuickDraw
  978. > >environement, it is incredible. Moreover, many examples are exactly
  979. > Well, I know nothing about the book, so I can't comment on that.  But
  980. > I will say that not using the WITH statement is a good idea.  The WITH
  981. > statement leads to lots of very subtle errors, and generally should
  982. > be avoided.
  983. >    Peter.
  984. > -- 
  985. > _______________________________________________________________________
  986. > Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  987.  
  988.  
  989. The with satement should not be avoided.  It should, however, be used
  990. with
  991. care.  One can get in trouble using it by not knowing what record a
  992. field
  993. belongs to.  I usually use it only when a line of code becomes too
  994. long.
  995.  
  996. Daniel W. Rickey
  997. drickey@.irus.rri.uwo.ca
  998.  
  999. Imaging Research Laboratories
  1000. The J.P. Robarts Research Institute
  1001. 100 Perth Drive
  1002. London, Ontario
  1003. CANADA  N6A 5K8
  1004.  
  1005. +++++++++++++++++++++++++++
  1006.  
  1007. >From casgrain@ERE.UMontreal.CA (Casgrain Philippe)
  1008. Date: Thu, 24 Feb 1994 16:25:05 GMT
  1009. Organization: Universite de Montreal
  1010.  
  1011. drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1012.  
  1013. >>In article <2kh51i$50q@ncrpda.curtin.edu.au>
  1014. >>peter@ncrpda.curtin.edu.au (Peter N Lewis) writes:
  1015. >> I will say that not using the WITH statement is a good idea.  The WITH
  1016. >> statement leads to lots of very subtle errors, and generally should
  1017. >> be avoided.
  1018. >The with satement should not be avoided.  It should, however, be used with
  1019. >care.  One can get in trouble using it by not knowing what record a field
  1020. >belongs to.  I usually use it only when a line of code becomes too long.
  1021.  
  1022. I agree with Peter: what if you use 'with' to de-reference a handle (a 
  1023. common use), and the code between the 'with' and its 'end' moves
  1024. memory? Now that could lead to nasty errors, would'nt it!
  1025.  
  1026. If you want to use the "with" statement, IMHO you better be sure that
  1027. your code does not move memory inside the statement. If you are not sure,
  1028. do not use "with".
  1029.  
  1030. Philippe
  1031. --
  1032. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1033. Philippe Casgrain              Etudiant-Chercheur      Casgrain@ERE.UMontreal.CA
  1034. Departement des Sciences Biologiques                      Universite de Montreal
  1035.                   "Imitation is the sincerest form of flattery"
  1036.  
  1037. +++++++++++++++++++++++++++
  1038.  
  1039. >From cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton)
  1040. Date: Thu, 24 Feb 1994 11:37:20 -0600
  1041. Organization: Academic Computing, UT-Houston
  1042.  
  1043. In article <lemieuse.762107105@alize.ERE.UMontreal.CA>,
  1044. casgrain@ERE.UMontreal.CA (Casgrain Philippe) wrote:
  1045.  
  1046. > drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1047. > >>In article <2kh51i$50q@ncrpda.curtin.edu.au>
  1048. > >>peter@ncrpda.curtin.edu.au (Peter N Lewis) writes:
  1049. > >> I will say that not using the WITH statement is a good idea.  The WITH
  1050. > >> statement leads to lots of very subtle errors, and generally should
  1051. > >> be avoided.
  1052. > >The with satement should not be avoided.  It should, however, be used with
  1053. > >care.  One can get in trouble using it by not knowing what record a field
  1054. > >belongs to.  I usually use it only when a line of code becomes too long.
  1055. > I agree with Peter: what if you use 'with' to de-reference a handle (a 
  1056. > common use), and the code between the 'with' and its 'end' moves
  1057. > memory? Now that could lead to nasty errors, would'nt it!
  1058. > If you want to use the "with" statement, IMHO you better be sure that
  1059. > your code does not move memory inside the statement. If you are not sure,
  1060. > do not use "with".
  1061.  
  1062. Code moving memory has nothing to do with the "safety" of a with statement.
  1063. "With" is a compile-time construct that allows a shorthand notation to be
  1064. used for complex record references. The COMPILER uses the identifier
  1065. specified in the with statement, coupled with the offsets of fields within
  1066. the record to generate  references for the record fields you refer to in
  1067. the body of the with statement. 
  1068.  
  1069. It has ABSOLUTELY nothing to do with what happens at runtime. It is merely
  1070. a shorthand convenience for the author of Pascal code to use. The same code
  1071. is generated whether a with statement or fully qualified record reference
  1072. is used.
  1073.  
  1074. The single biggest problem I have with the with statement is that it makes
  1075. porting Pascal code to some other language a real pain if you are trying to
  1076. automate the conversion. Not to mention the obvious readability
  1077. problems....
  1078.  
  1079. --_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  1080. Chuck Shotton                             \ 
  1081. Assistant Director, Academic Computing     \   "Are we there yet?"
  1082. U. of Texas Health Science Center Houston   \ 
  1083. cshotton@oac.hsc.uth.tmc.edu  (713) 794-5650 \ 
  1084. _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\-_-_-_-_-_-_-_-_-_-_-_-_-
  1085.  
  1086. +++++++++++++++++++++++++++
  1087.  
  1088. >From casgrain@ERE.UMontreal.CA (Casgrain Philippe)
  1089. Date: Thu, 24 Feb 1994 19:38:38 GMT
  1090. Organization: Universite de Montreal
  1091.  
  1092. cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1093. >Code moving memory has nothing to do with the "safety" of a with statement.
  1094. That's not what Scott Knaster says (in "How to write Macintosh Software, 3rd
  1095. edition). This book is the origin of my remarks.
  1096.  
  1097. Knaster used MPW Pascal, and I re-did his examples with MPW and THINK, and
  1098. you will be surprised to know that a "with" statement actually de-references
  1099. the handle/pointer/whatever in the compiled code. Hence the "may move
  1100. memory" warning.
  1101.  
  1102. If you want, I will be happy to fish out the exact quotation for you.
  1103.  
  1104. Philippe
  1105.  
  1106. B
  1107. >"With" is a compile-time construct that allows a shorthand notation to be
  1108. B
  1109. >used for complex record references. The COMPILER uses the identifier
  1110. >specified in the with statement, coupled with the offsets of fields within
  1111. >the record to generate  references for the record fields you refer to in
  1112. >the body of the with statement. 
  1113.  
  1114. >It has ABSOLUTELY nothing to do with what happens at runtime. It is merely
  1115. >a shorthand convenience for the author of Pascal code to use. The same code
  1116. >is generated whether a with statement or fully qualified record reference
  1117. >is used.
  1118.  
  1119. >The single biggest problem I have with the with statement is that it makes
  1120. >porting Pascal code to some other language a real pain if you are trying to
  1121. >automate the conversion. Not to mention the obvious readability
  1122. >problems....
  1123.  
  1124. >--_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  1125. >Chuck Shotton                             \ 
  1126. >Assistant Director, Academic Computing     \   "Are we there yet?"
  1127. >U. of Texas Health Science Center Houston   \ 
  1128. >cshotton@oac.hsc.uth.tmc.edu  (713) 794-5650 \ 
  1129. >_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\-_-_-_-_-_-_-_-_-_-_-_-_-
  1130. --
  1131. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1132. Philippe Casgrain              Etudiant-Chercheur      Casgrain@ERE.UMontreal.CA
  1133. Departement des Sciences Biologiques                      Universite de Montreal
  1134.                   "Imitation is the sincerest form of flattery"
  1135.  
  1136. +++++++++++++++++++++++++++
  1137.  
  1138. >From lylem@vax.sonoma.edu (Michael R. Lyle)
  1139. Date: Thu, 24 Feb 1994 13:00:33 -0800
  1140. Organization: Sonoma State University
  1141.  
  1142. > B
  1143. > >"With" is a compile-time construct that allows a shorthand notation to be
  1144. > B
  1145. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1146. > Philippe Casgrain              Etudiant-Chercheur      Casgrain@ERE.UMontreal.CA
  1147. > Departement des Sciences Biologiques                      Universite de Montreal
  1148. >                   "Imitation is the sincerest form of flattery"
  1149.  
  1150. Please note that the Pascal _STANDARD_ says that _with_ is executable.  The
  1151. orignal (Wirth) documents implied that it was only syntactic sugar, but all
  1152. implementations made it executable, so the standard was changed in about
  1153. 1981.
  1154.  
  1155. Note:  This means that once you have done _with_ on any data item, its
  1156. address is probably in a register and that address will be used to
  1157. reference it from then until the end of the scope of the _with_ statement. 
  1158. If the actual data item moves, your reference may well be invalid.
  1159.  
  1160. >From an old Pascal teacher who still prefers it to C and C++....
  1161. -- 
  1162. Michael R. Lyle
  1163. Sonoma State University
  1164. Rohnert Park, CA 94928
  1165. lylem@sonoma.edu
  1166.  
  1167. +++++++++++++++++++++++++++
  1168.  
  1169. >From siegel@netcom.com (Rich Siegel)
  1170. Date: Fri, 25 Feb 1994 01:44:43 GMT
  1171. Organization: Bare Bones Software
  1172.  
  1173. In article <cshotton-240294113720@oac2.hsc.uth.tmc.edu> cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1174. >
  1175. >Code moving memory has nothing to do with the "safety" of a with statement.
  1176. >"With" is a compile-time construct that allows a shorthand notation to be
  1177. >used for complex record references. The COMPILER uses the identifier
  1178. >specified in the with statement, coupled with the offsets of fields within
  1179. >the record to generate  references for the record fields you refer to in
  1180. >the body of the with statement. 
  1181. >
  1182. >It has ABSOLUTELY nothing to do with what happens at runtime. It is merely
  1183. >a shorthand convenience for the author of Pascal code to use. The same code
  1184. >is generated whether a with statement or fully qualified record reference
  1185. >is used.
  1186.  
  1187. Oh, you think so, do you? :-)
  1188.  
  1189. Here is a simple counter-example.
  1190.  
  1191. Given this Pascal code:
  1192.  
  1193. program Main;
  1194.  
  1195.  type
  1196.   RecordType = record
  1197.     fieldA: Integer;
  1198.     fieldB: Integer;
  1199.    end;
  1200.   RecordPtr = ^RecordType;
  1201.   RecordHandle = ^RecordPtr;
  1202.  
  1203.  procedure P (r: RecordHandle);
  1204.  begin
  1205.   with r^^ do
  1206.    begin
  1207.     fieldA := 10;
  1208.     fieldB := 20;
  1209.    end;
  1210.  end;
  1211.  
  1212.  procedure Q (r: RecordHandle);
  1213.  begin
  1214.   r^^.fieldA := 20;
  1215.   r^^.fieldB := 40;
  1216.  end;
  1217.  
  1218.  var
  1219.   r: RecordHandle;
  1220.  
  1221. begin
  1222.  r := RecordHandle(NewHandle(SizeOf(RecordType)));
  1223.  p(r);
  1224.  q(r);
  1225. end.
  1226.  
  1227. THINK Pascal 2.0 and later will generate the following code for P and
  1228. Q, respectively:
  1229.  
  1230.   P
  1231.      +0000    *LINK       A6,#$0000
  1232.      +0004     MOVE.L     A4,-(A7)
  1233.      +0006     MOVEA.L    $0008(A6),A0
  1234.      +000A     MOVEA.L    (A0),A4
  1235.      +000C     MOVE.W     #$000A,(A4)
  1236.      +0010     MOVE.W     #$0014,$0002(A4)
  1237.      +0016     MOVEA.L    (A7)+,A4
  1238.      +0018     UNLK       A6
  1239.      +001A     MOVE.L     (A7)+,(A7)
  1240.      +001C     RTS
  1241.      
  1242.   Q
  1243.      +0000     LINK       A6,#$0000
  1244.      +0004     MOVEA.L    $0008(A6),A0
  1245.      +0008     MOVEA.L    (A0),A0
  1246.      +000A     MOVE.W     #$0014,(A0)
  1247.      +000E     MOVEA.L    $0008(A6),A0
  1248.      +0012     MOVEA.L    (A0),A0
  1249.      +0014     MOVE.W     #$0028,$0002(A0)
  1250.      +001A     UNLK       A6
  1251.      +001C     MOVE.L     (A7)+,(A7)
  1252.      +001E     RTS
  1253.  
  1254. Note that in P, the generated code places p^ into a register (a4 in this
  1255. case), and then stores relative to the register.
  1256.  
  1257. In Q, p^ is repeatedly generated into a temp (a0, in this case) which
  1258. is then used to store.
  1259.  
  1260. The WITH-clause is not a simple syntactic shorthand. The compiler is
  1261. free to use the presence of a WITH-clause as a hint to the code
  1262. generator to generate more efficient code, and most 68K Pascal
  1263. compilers I've seen avail themselves of this hint.
  1264.  
  1265. R.
  1266.  
  1267. -- 
  1268. Rich Siegel % siegel@netcom.com    % Principal, Bare Bones Software
  1269. --> For information about BBEdit, finger bbedit@world.std.com <--
  1270.  
  1271. "He then proceeded to give a history of the universe, in real time."
  1272.  
  1273. +++++++++++++++++++++++++++
  1274.  
  1275. >From drickey@irus.rri.uwo.ca (Daniel W. Rickey)
  1276. Date: 25 Feb 1994 15:21:20 GMT
  1277. Organization: Imaging Research Labs
  1278.  
  1279. In article <siegelCLrBIn.Cou@netcom.com>
  1280. siegel@netcom.com (Rich Siegel) writes:
  1281.  
  1282. > The WITH-clause is not a simple syntactic shorthand. The compiler is
  1283. > free to use the presence of a WITH-clause as a hint to the code
  1284. > generator to generate more efficient code, and most 68K Pascal
  1285. > compilers I've seen avail themselves of this hint.
  1286. > R.
  1287. > -- 
  1288. > Rich Siegel % siegel@netcom.com        % Principal, Bare Bones Software
  1289.  
  1290.  
  1291. Well, one learns something new everyday.  I too thought the with
  1292. statement did not affect the code generation.  Does this mean that we
  1293. should never use a With statement to dereference a handle?  I tend to
  1294. use the With statement only to dereference pointers.
  1295.  
  1296. Daniel W. Rickey
  1297. drickey@.irus.rri.uwo.ca
  1298.  
  1299. Imaging Research Laboratories
  1300. The J.P. Robarts Research Institute
  1301. 100 Perth Drive
  1302. London, Ontario
  1303. CANADA  N6A 5K8
  1304.  
  1305. +++++++++++++++++++++++++++
  1306.  
  1307. >From pottier@galion.ens.fr (Francois Pottier)
  1308. Date: 25 Feb 1994 16:27:09 GMT
  1309. Organization: Ecole Normale Superieure, PARIS, France
  1310.  
  1311. In article <2kh51i$50q@ncrpda.curtin.edu.au>,
  1312. Peter N Lewis <peter@ncrpda.curtin.edu.au> wrote:
  1313.  
  1314. >I will say that not using the WITH statement is a good idea.  The WITH
  1315. >statement leads to lots of very subtle errors, and generally should
  1316. >be avoided.
  1317.  
  1318. Well, I beg to differ. I'd rather say: the Mac Memory Manager leads to lots
  1319. of very subtle errors, and you should generally avoid using
  1320.   with theHandle do
  1321. or
  1322.   with theObject do
  1323. constructs, unless you are certain not to move memory.
  1324.  
  1325. Also, OOP can be dangerous. Since every method contains a implicit
  1326. "with Self do" construct, moving memory could move your object from under you.
  1327.  
  1328. If you know about those pitfalls and carefully avoid them, there is nothing
  1329. wrong with the with construct... For instance, when filling a parameter
  1330. block, using a with construct is much more elegant than the C way:
  1331.  
  1332. paramBlock.ioVRefNum = ...
  1333. paramBlock.ioDirID = ...
  1334.  
  1335. which is very redundant.
  1336.  
  1337. Cheers,
  1338.  
  1339. -- 
  1340. Francois Pottier            ___ ___  _    _  / ___  ___    ___
  1341. pottier@dmi.ens.fr       /_  /__/ /_|  /| / /  / /  / / /__
  1342.               /   / \  /  | / |/ /___ /__/ / ___/ _
  1343.                           /
  1344.  
  1345. +++++++++++++++++++++++++++
  1346.  
  1347. >From mxmora@unix.sri.com (Matt Mora)
  1348. Date: 25 Feb 1994 08:27:47 -0800
  1349. Organization: SRI International, Menlo Park, CA
  1350.  
  1351. In article <2kl51g$9hb@falcon.ccs.uwo.ca> drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1352. >In article <siegelCLrBIn.Cou@netcom.com>
  1353. >siegel@netcom.com (Rich Siegel) writes:
  1354.  
  1355. >> The WITH-clause is not a simple syntactic shorthand. The compiler is
  1356. >> free to use the presence of a WITH-clause as a hint to the code
  1357. >> generator to generate more efficient code, and most 68K Pascal
  1358. >> compilers I've seen avail themselves of this hint.
  1359.  
  1360. >Well, one learns something new everyday.  I too thought the with
  1361. >statement did not affect the code generation.  Does this mean that we
  1362. >should never use a With statement to dereference a handle?  I tend to
  1363. >use the With statement only to dereference pointers.
  1364.  
  1365.  
  1366. Works with handles just fine. Just lock them first. I was supprised to see
  1367. Peter bash this cool feature of Pascal. I was told that features like
  1368. this help Pascal compilers optimize code better than c ever could.
  1369.  
  1370. Xavier
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378. -- 
  1379. ___________________________________________________________
  1380. Matthew Xavier Mora                    Matt_Mora@qm.sri.com
  1381. SRI International                       mxmora@unix.sri.com
  1382. 333 Ravenswood Ave                    Menlo Park, CA. 94025
  1383.  
  1384. +++++++++++++++++++++++++++
  1385.  
  1386. >From casgrain@ERE.UMontreal.CA (Casgrain Philippe)
  1387. Date: Fri, 25 Feb 1994 19:24:45 GMT
  1388. Organization: Universite de Montreal
  1389.  
  1390. pottier@galion.ens.fr (Francois Pottier) writes:
  1391.  
  1392. >Well, I beg to differ. I'd rather say: the Mac Memory Manager leads to lots
  1393. >of very subtle errors, and you should generally avoid using
  1394. >  with theHandle do
  1395. >or
  1396. >  with theObject do
  1397. >constructs, unless you are certain not to move memory.
  1398.  
  1399. Well ;-> if you are not certain about the moving memory stuff (some 
  1400. toolbox calls move memory indirectly, by calling other toolbox calls that
  1401. themselves move memory), you can always lock your handles before the
  1402. "with" (HLock) and unlock them after (HUnlock). Be careful not to leave
  1403. your handles locked for too long, as your heap will become fragmented.
  1404.  
  1405. On a related note, the TB calls that move memory usually are documented
  1406. as such (for example, there's the little "memory chip" icon in THINK
  1407. Reference), but there are probably some errors and omissions, although I
  1408. can't think of any offhand. Anyone? Anyone?
  1409.  
  1410. Philippe
  1411. --
  1412. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1413. Philippe Casgrain              Etudiant-Chercheur      Casgrain@ERE.UMontreal.CA
  1414. Departement des Sciences Biologiques                      Universite de Montreal
  1415.                   "Imitation is the sincerest form of flattery"
  1416.  
  1417. +++++++++++++++++++++++++++
  1418.  
  1419. >From siegel@netcom.com (Rich Siegel)
  1420. Date: Fri, 25 Feb 1994 20:20:44 GMT
  1421. Organization: Bare Bones Software
  1422.  
  1423. In article <2kl51g$9hb@falcon.ccs.uwo.ca> drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1424. >
  1425. >Well, one learns something new everyday.  I too thought the with
  1426. >statement did not affect the code generation.  Does this mean that we
  1427. >should never use a With statement to dereference a handle?  I tend to
  1428. >use the With statement only to dereference pointers.
  1429.  
  1430. "never" is a little strong. Use it any way you like, but just be aware
  1431. of the implications when you do.
  1432.  
  1433. R.
  1434.  
  1435. -- 
  1436. Rich Siegel % siegel@netcom.com    % Principal, Bare Bones Software
  1437. --> For information about BBEdit, finger bbedit@world.std.com <--
  1438.  
  1439. "He then proceeded to give a history of the universe, in real time."
  1440.  
  1441. +++++++++++++++++++++++++++
  1442.  
  1443. >From cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton)
  1444. Date: Fri, 25 Feb 1994 19:43:38 -0600
  1445. Organization: UT Houston Academic Computing
  1446.  
  1447. In article <siegelCLrBIn.Cou@netcom.com>, siegel@netcom.com (Rich Siegel)
  1448. wrote:
  1449.  
  1450. > In article <cshotton-240294113720@oac2.hsc.uth.tmc.edu> cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1451. > Oh, you think so, do you? :-)
  1452. > Here is a simple counter-example.
  1453. > [code snipped]
  1454. > The WITH-clause is not a simple syntactic shorthand. The compiler is
  1455. > free to use the presence of a WITH-clause as a hint to the code
  1456. > generator to generate more efficient code, and most 68K Pascal
  1457. > compilers I've seen avail themselves of this hint.
  1458.  
  1459. You are correct. Mac compiler writers have implemented the "with" in a
  1460. non-safe fashion. The Jensen & Wirth book never indicates how code is to be
  1461. generated for this statement, but very clearly identifies it as a syntactic
  1462. short cut rather than a cue to the code generator. To me, that should
  1463. indicate that the non-safe code generated by Mac compilers when
  1464. dereferenced pointers and handles are "withed" is not exactly compliant
  1465. with the standard.
  1466.  
  1467. -----------------------------------------------------------------------
  1468. Chuck Shotton
  1469. cshotton@oac.hsc.uth.tmc.edu                           "I am NOT here."
  1470.  
  1471. +++++++++++++++++++++++++++
  1472.  
  1473. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  1474. Date: 27 Feb 1994 12:46:09 +0800
  1475. Organization: NCRPDA, Curtin University
  1476.  
  1477. mxmora@unix.sri.com (Matt Mora) writes:
  1478.  
  1479. >Works with handles just fine. Just lock them first. I was supprised to see
  1480. >Peter bash this cool feature of Pascal. I was told that features like
  1481. >this help Pascal compilers optimize code better than c ever could.
  1482.  
  1483. True, that and for loops and generally many fewer pointers (pointers confuse
  1484. the heck out of optimizers in general).
  1485.  
  1486. The with statement has its place, but it must be used very causiously.  It
  1487. can cause problems if you do "with h^" and the handle moves inside the with
  1488. statement.  It can cause problems if you "with rec", and rec contains fields
  1489. that clash with global or local variables (this is especially painful when
  1490. global or local variables clash with object variables, since THINK Pascal
  1491. puts in a "with self" implicitly).  It's also interesting to note that most
  1492. compilers won't generate less efficient code for these two:
  1493.  
  1494. pb.a := 1;
  1495. pb.b := 2;
  1496. ..
  1497.  
  1498. as compared with
  1499.  
  1500. with pb do begin
  1501.   a := 1;
  1502.   b := 2;
  1503.   ...
  1504. end;
  1505.  
  1506. In any event, my advice, especially to beginning programmers is to 
  1507. avoid the with statement as a general rule until you really understand
  1508. what it does and what its dangers are.  Of course, you can't avoid the
  1509. implicit "with self", so you better learn about those dangers pretty quick!
  1510.    Peter.
  1511. -- 
  1512. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  1513.  
  1514. +++++++++++++++++++++++++++
  1515.  
  1516. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  1517. Date: 27 Feb 1994 12:49:57 +0800
  1518. Organization: NCRPDA, Curtin University
  1519.  
  1520. casgrain@ERE.UMontreal.CA (Casgrain Philippe) writes:
  1521.  
  1522. >On a related note, the TB calls that move memory usually are documented
  1523. >as such (for example, there's the little "memory chip" icon in THINK
  1524. >Reference), but there are probably some errors and omissions, although I
  1525. >can't think of any offhand. Anyone? Anyone?
  1526.  
  1527. My policy is to assume everything can move memory except BlockMove, 
  1528. PBRead and PBWrite (and FSRead and FSWrite).  As a general rule, they
  1529. are the only common routines that you use with handle data that are
  1530. handle-safe.  Remember that you aren't only dealing with what the OS does
  1531. now, but also what it might do in the future (witness SysBeep), and
  1532. also what broken inits (like some from Apple! ;-) that change the
  1533. memory-safeness of routines.
  1534.    Peter.
  1535. -- 
  1536. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  1537.  
  1538. +++++++++++++++++++++++++++
  1539.  
  1540. >From quinn@uniwa.uwa.edu.au (Quinn "The Eskimo!")
  1541. Date: 27 Feb 1994 13:29:06 +0800
  1542. Organization: The University of Western Australia
  1543.  
  1544. mxmora@unix.sri.com (Matt Mora) writes:
  1545.  
  1546. >[...] I was supprised to see
  1547. >Peter bash this cool feature of Pascal. I was told that features like
  1548. >this help Pascal compilers optimize code better than c ever could.
  1549.  
  1550. But Pete uses Pascal because it's safer, not because it produces better
  1551. code.  The with statement is wildly unsafe because it brings identifiers
  1552. into scope with very little warning.  [In that respect it's very like
  1553. Pascal's uses clause which is also braindead, especially wehn compared
  1554. to Modula 2's import/export mechanism.]
  1555.  
  1556. What I'd like to see is the with statement redone so that it doesn't
  1557. introduce new identifiers invisibly.  For example instead of doing
  1558. this...
  1559.  
  1560.   with graf_ptr^.pnLoc do begin
  1561.     frog := h;
  1562.   end; (* with *)
  1563.  
  1564. you get something more like this...
  1565.  
  1566.   with my_pn_loc ::= graf_ptr^.pnLoc do
  1567.     frog := my_pn_loc.h;
  1568.   end-with;
  1569.  
  1570. The second version introduces a name for the temporary result, which
  1571. you then use in a qualified fashion.  Much safer IMHO.
  1572.  
  1573. --
  1574. Quinn "The Eskimo!"      <quinn@cs.uwa.edu.au>     "Support HAVOC!"
  1575. Department of Computer Science, The University of Western Australia
  1576.   I hate unix!!!  I hate nn!!!  I wan't my static IP number back ):
  1577. -- 
  1578.  
  1579. Quinn "The Eskimo!"      <quinn@cs.uwa.edu.au>     "Support HAVOC!"
  1580. Department of Computer Science, The University of Western Australia
  1581.   I hate unix!!!
  1582.  
  1583. +++++++++++++++++++++++++++
  1584.  
  1585. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  1586. Date: 28 Feb 1994 11:25:24 +0800
  1587. Organization: NCRPDA, Curtin University
  1588.  
  1589. cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1590.  
  1591. >You are correct. Mac compiler writers have implemented the "with" in a
  1592.  
  1593. It's not just Mac compilers, it's how every compiler I've ever seen (and
  1594. indeed every compiler I've ever written!) has implemented the with statement.
  1595. If thats not part of the standard, then it's the standard that is wrong.
  1596. But the fact is that it doesn't matter which way it's implemented, this
  1597. would still be dangerous:
  1598.  
  1599. with p^ do begin
  1600.   Dispose(p);
  1601.   x := 5;
  1602. end;
  1603.  
  1604. Where x is a local variable and a field of p^.  The only reason it is
  1605. unsafe with handles is because of the Mac's treatment of handles as
  1606. movable.  But it would still be unsafe under other OSes if other conditions
  1607. like the above happened.
  1608.    Peter.
  1609. -- 
  1610. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  1611.  
  1612. +++++++++++++++++++++++++++
  1613.  
  1614. >From D.A.G.Gillies@bradford.ac.uk (DAG GILLIES)
  1615. Date: Mon, 28 Feb 1994 13:28:18 GMT
  1616. Organization: University of Bradford, UK
  1617.  
  1618. In article <2kl8u3$ao@unix.sri.com> mxmora@unix.sri.com (Matt Mora) writes:
  1619. >In article <2kl51g$9hb@falcon.ccs.uwo.ca> drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1620. >>In article <siegelCLrBIn.Cou@netcom.com>
  1621. >>siegel@netcom.com (Rich Siegel) writes:
  1622. >
  1623. >>> The WITH-clause is not a simple syntactic shorthand. The compiler is
  1624. >>> free to use the presence of a WITH-clause as a hint to the code
  1625. >>> generator to generate more efficient code, and most 68K Pascal
  1626. >>> compilers I've seen avail themselves of this hint.
  1627. >
  1628. >>Well, one learns something new everyday.  I too thought the with
  1629. >>statement did not affect the code generation.  Does this mean that we
  1630. >>should never use a With statement to dereference a handle?  I tend to
  1631. >>use the With statement only to dereference pointers.
  1632. >
  1633. >
  1634. >Works with handles just fine. Just lock them first. I was supprised to see
  1635. >Peter bash this cool feature of Pascal. I was told that features like
  1636. >this help Pascal compilers optimize code better than c ever could.
  1637. >
  1638.  
  1639. Am I missing something here, or am I mistaken when I recall that in the first
  1640. few pages of Volume I of (old) Inside Mac, there is a specific warning
  1641. about locking handles before dereferencing them, and that the Pascal WITH
  1642. statement can cause an implicit dereference. There was a code fragment
  1643. along the lines of
  1644.  
  1645. HLock(aHandle)
  1646.  
  1647. WITH aHandle DO
  1648.     ...
  1649.     ...
  1650.     ...
  1651.  
  1652. HUnlock(aHandle)
  1653.  
  1654.  
  1655. I mean, if it's in IM, why all the controversy?
  1656.  
  1657.  
  1658. ______________________________________________________
  1659. David A. G. Gillies     (D.A.G.Gillies@bradford.ac.uk)
  1660. (c) 1994 Wittgenstein's Amazing Underwater Supermarket
  1661.  
  1662. ---------------REPLIES VIA EMAIL PLEASE---------------
  1663. _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  1664.  
  1665. +++++++++++++++++++++++++++
  1666.  
  1667. >From neeri@iis.ee.ethz.ch (Matthias Neeracher)
  1668. Date: 28 Feb 94 17:38:00
  1669. Organization: Integrated Systems Laboratory, ETH, Zurich
  1670.  
  1671. In article <cshotton-250294194338@oacslip202.hsc.uth.tmc.edu>, cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1672.  
  1673. > In article <siegelCLrBIn.Cou@netcom.com>, siegel@netcom.com (Rich Siegel)
  1674. > wrote:
  1675. >> The WITH-clause is not a simple syntactic shorthand. The compiler is
  1676. >> free to use the presence of a WITH-clause as a hint to the code
  1677. >> generator to generate more efficient code, and most 68K Pascal
  1678. >> compilers I've seen avail themselves of this hint.
  1679.  
  1680. > You are correct. Mac compiler writers have implemented the "with" in a
  1681. > non-safe fashion. The Jensen & Wirth book never indicates how code is to be
  1682. > generated for this statement, but very clearly identifies it as a syntactic
  1683. > short cut rather than a cue to the code generator. To me, that should
  1684. > indicate that the non-safe code generated by Mac compilers when
  1685. > dereferenced pointers and handles are "withed" is not exactly compliant
  1686. > with the standard.
  1687.  
  1688. A few comments:
  1689.  
  1690.  - Jensen & Wirth is not the Pascal Standard.
  1691.  - At least one ETH Modula-2 compiler, which certainly was authorized by Wirth,
  1692.    does no register allocation except to use two of the address registers
  1693.    for the two innermost WITH statements.
  1694.  - I would suspect that something similar was done for many Pascal compilers.
  1695.  - The reason why this is not mentioned is probably that J&W were not concerned
  1696.    with such problems, and indeed, this problem is not very important outside
  1697.    of a handle based environment.
  1698.  
  1699. Matthias
  1700.  
  1701. -----
  1702. Matthias Neeracher                                neeri@iis.ee.ethz.ch
  1703.    "One fine day in my odd past..." -- Pixies, _Planet of Sound_
  1704.  
  1705. +++++++++++++++++++++++++++
  1706.  
  1707. >From peirce@outpost.SF-Bay.org (Michael Peirce)
  1708. Date: Mon, 28 Feb 94 10:42:19 PST
  1709. Organization: Peirce Software, Inc.
  1710.  
  1711.  
  1712. In article <cshotton-250294194338@oacslip202.hsc.uth.tmc.edu> (comp.sys.mac.programmer), cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1713. > In article <siegelCLrBIn.Cou@netcom.com>, siegel@netcom.com (Rich Siegel)
  1714. > wrote:
  1715. > > In article <cshotton-240294113720@oac2.hsc.uth.tmc.edu> cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1716. > > 
  1717. > > Oh, you think so, do you? :-)
  1718. > > 
  1719. > > Here is a simple counter-example.
  1720. > > [code snipped]
  1721. > > The WITH-clause is not a simple syntactic shorthand. The compiler is
  1722. > > free to use the presence of a WITH-clause as a hint to the code
  1723. > > generator to generate more efficient code, and most 68K Pascal
  1724. > > compilers I've seen avail themselves of this hint.
  1725. > You are correct. Mac compiler writers have implemented the "with" in a
  1726. > non-safe fashion. The Jensen & Wirth book never indicates how code is to be
  1727. > generated for this statement, but very clearly identifies it as a syntactic
  1728. > short cut rather than a cue to the code generator. To me, that should
  1729. > indicate that the non-safe code generated by Mac compilers when
  1730. > dereferenced pointers and handles are "withed" is not exactly compliant
  1731. > with the standard.
  1732.  
  1733. Don't blame just Mac Pascal compilers.  I know of at least one PDP-11
  1734. Pascal compiler that does this same thing.  I expect there are others.
  1735. (I think the VAX Pascal compiler did this too)
  1736.  
  1737. Frankly, I wish there was a similar construct in c - or at least C
  1738. compilers that were smart enough to dereference a struct into a register
  1739. instead of constantly redereferencing.  The Pascal code is much more
  1740. efficient in this case.  (A good example of this is filling in a BIG
  1741. parameter block).
  1742.  
  1743.  
  1744. -- Michael Peirce        -- peirce@outpost.sf-bay.org
  1745. -- Peirce Software, Inc. -- 719 Hibiscus Place, Suite 301
  1746. --                       -- San Jose, California USA 95117
  1747. -- Makers of: Smoothie & -- voice: +1.408.244.6554 fax: +1.408.244.6882
  1748. --    Peirce Print Tools -- AppleLink: peirce & America Online: AFC Peirce
  1749.  
  1750. +++++++++++++++++++++++++++
  1751.  
  1752. >From platypus@cirrus.som.cwru.edu (Gary Kacmarcik)
  1753. Date: 02 Mar 1994 01:01:15 GMT
  1754. Organization: Case Western Reserve University, Cleveland, Ohio (USA)
  1755.  
  1756. In article <CNjbKKKX.peuobu@outpost.SF-Bay.org> peirce@outpost.SF-Bay.org (Michael Peirce) writes:
  1757. > In article <cshotton-250294194338@oacslip202.hsc.uth.tmc.edu> (comp.sys.mac.programmer), cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1758. > > In article <siegelCLrBIn.Cou@netcom.com>, siegel@netcom.com (Rich Siegel)
  1759. > > wrote:
  1760. > > > 
  1761. > > > The WITH-clause is not a simple syntactic shorthand. The compiler is
  1762. > > > free to use the presence of a WITH-clause as a hint to the code
  1763. > > > generator to generate more efficient code, and most 68K Pascal
  1764. > > > compilers I've seen avail themselves of this hint.
  1765. > > 
  1766. > > You are correct. Mac compiler writers have implemented the "with" in a
  1767. > > non-safe fashion. The Jensen & Wirth book never indicates how code is to be
  1768. > > generated for this statement, but very clearly identifies it as a syntactic
  1769. > > short cut rather than a cue to the code generator. To me, that should
  1770. > > indicate that the non-safe code generated by Mac compilers when
  1771. > > dereferenced pointers and handles are "withed" is not exactly compliant
  1772. > > with the standard.
  1773. >
  1774. > Don't blame just Mac Pascal compilers.  I know of at least one PDP-11
  1775. > Pascal compiler that does this same thing.  I expect there are others.
  1776. > (I think the VAX Pascal compiler did this too)
  1777. >
  1778. > Frankly, I wish there was a similar construct in c - or at least C
  1779. > compilers that were smart enough to dereference a struct into a register
  1780. > instead of constantly redereferencing.  The Pascal code is much more
  1781. > efficient in this case.  (A good example of this is filling in a BIG
  1782. > parameter block).
  1783.  
  1784. ummm...
  1785.  
  1786. i don't understand your comment that Pascal is "much more efficient"
  1787. in this case.  without the "with" statement, comparable compilers
  1788. should generate code which is equally "bad".
  1789.  
  1790. if you have the "with" statement in Pascal, then you need to add
  1791. the equivalent in C: which is an assignment statement which saves
  1792. the dereferenced handle/ptr.  again, the code should be comparable.
  1793. (if not, you should get a better compiler ;-)
  1794.  
  1795. C expects you to explicitly store the value in a temp variable, which
  1796. is exactly what the "with" statement (as described above) does.  i
  1797. don't see any real need for a "with" statement - it makes the
  1798. code slightly less explicit and potentially confusing (eg: with
  1799. multiple "with"s into structures that have fields/records with the
  1800. same name).
  1801.  
  1802. being explicit (either in C or Pascal) makes the code more readable:
  1803. i detest reading Pascal code where the programmer uses multiple
  1804. nested "with" statements because it makes it much more difficult to
  1805. identify which struct the field belongs to.
  1806.  
  1807.  
  1808. -gary j kacmarcik
  1809. platypus@curie.ces.cwru.edu
  1810.  
  1811.  
  1812.  
  1813. ---------------------------
  1814.  
  1815. End of C.S.M.P. Digest
  1816. **********************
  1817.  
  1818.  
  1819.  
  1820.